package com.liuyi.netty.im.test.lychat.config.thread;

import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.aop.interceptor.SimpleAsyncUncaughtExceptionHandler;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;

import java.util.concurrent.Executor;

/**
 * 异步线程池配置
 * <pre>
 *     如果要开启 @Async 注解，需要额外使用 @EnableAsync
 *     这里暂时不开启 @EnableAsync，使用该种配置方式的时候
 *     @Async 注解不会使用默认线程池，而是使用本配置类配置的线程池
 * </pre>
 */
@Configuration
public class ThreadAsyncConfig implements AsyncConfigurer {


    @Override
    public Executor getAsyncExecutor() {
        return TaskPoolConfig.geTSaskExecutor();
    }

    @Override
    public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
        return new SimpleAsyncUncaughtExceptionHandler();
    }
}
